import { BasicColumn, FormSchema } from '@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: '服务器名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '主机地址',
    dataIndex: 'ip',
    width: 120,
  },
  {
    title: '端口',
    dataIndex: 'port',
    width: 80,
  },
  {
    title: '用户名',
    dataIndex: 'username',
    width: 100,
  },
  {
    title: '认证类型',
    dataIndex: 'auth_type',
    width: 100,
    customRender: ({ record }) => {
      const authTypes = {
        1: 'SSH密码',
        2: 'SSH密钥',
        3: 'RSYNC',
      };
      return authTypes[record.auth_type] || '未知';
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 80,
    customRender: ({ record }) => {
      return record.status === 10 ? '启用' : '禁用';
    },
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updated_at',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '服务器名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'ip',
    label: '主机地址',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '服务器名称',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'auth_type',
    label: '认证类型',
    component: 'Select',
    defaultValue: 1,
    required: true,
    colProps: { span: 24 },
    componentProps: {
      options: [
        { label: 'SSH密码', value: 1 },
        { label: 'SSH密钥', value: 2 },
        { label: 'RSYNC', value: 3 },
      ],
    },
  },
  {
    field: 'ip',
    label: '主机地址',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'port',
    label: '端口',
    component: 'InputNumber',
    required: true,
    defaultValue: 22,
    colProps: { span: 24 },
    componentProps: {
      min: 1,
      max: 65535,
    },
  },
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'password',
    label: '密码',
    component: 'InputPassword',
    required: false,
    colProps: { span: 24 },
    ifShow: ({ values }) => values.auth_type === 1 || values.auth_type === 3,
    label: ({ values }) => (values.auth_type === 3 ? 'RSYNC密码' : 'SSH密码'),
    helpMessage: '不填写则保持原密码不变',
  },
  {
    field: 'key',
    label: 'SSH私钥',
    component: 'InputTextArea',
    required: false,
    colProps: { span: 24 },
    ifShow: ({ values }) => values.auth_type === 2,
    componentProps: {
      rows: 4,
    },
    helpMessage: '不填写则保持原私钥不变',
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 10,
    required: true,
    colProps: { span: 24 },
    componentProps: {
      options: [
        { label: '启用', value: 10 },
        { label: '禁用', value: 20 },
      ],
    },
  },
];
